//
//  PersonInfoViewController.m
//  联付商圈
//
//  Created by apple on 2017/10/31.
//  Copyright © 2017年 lianfu. All rights reserved.
//

#import "PersonInfoViewController.h"
#import "UserInfoImgView.h"

@interface PersonInfoViewController ()<UITextFieldDelegate>
@property (nonatomic, strong) UIScrollView *infoScrollView;
///头像
@property (nonatomic, strong) UIImageView *headerImgView;
///第一部分资料
@property (nonatomic, strong) UserInfoImgView *topInfoView;
///第二部分资料
@property (nonatomic, strong) UserInfoImgView *bottomInfoView;
@end

@implementation PersonInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self buildMainInterface];
    [self loadData];
}

- (void)buildMainInterface
{
    [self.navigationItem setTitle:@"个人信息管理"];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(changeInfoFinish)];
    [self.navigationItem.rightBarButtonItem setTintColor:COLOR_RGBA(42, 218, 196, 1.0)];
    
    self.infoScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREENW, SCREENH - 113)];
    self.infoScrollView.contentSize = CGSizeMake(SCREENW, SCREENH - 113);
//    self.infoScrollView.scrollEnabled = 0;
    [self.view addSubview:_infoScrollView];
    
    self.headerImgView = [[UIImageView alloc] initWithFrame:CGRectMake(142.5 * FONTSIZE, 33 * FONTSIZE, 84 * FONTSIZE, 84 * FONTSIZE)];
    self.headerImgView.image = [UIImage imageNamed:@"header@2x"];
    self.headerImgView.layer.cornerRadius = self.headerImgView.frame.size.width / 2;
    self.headerImgView.layer.shadowColor = [UIColor colorWithRed:110/255.0 green:109/255.0 blue:124/255.0 alpha:1].CGColor;//阴影颜色
    self.headerImgView.layer.shadowOffset = CGSizeMake(0, 3);//偏移距离
    self.headerImgView.layer.shadowOpacity = 0.8;//不透明度
    self.headerImgView.layer.shadowRadius = 4;//半径
    [self.infoScrollView addSubview:_headerImgView];
    
    UILabel *changeHeaderLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 130 * FONTSIZE, SCREENW, 15 * FONTSIZE)];
    changeHeaderLabel.textAlignment = 1;
    changeHeaderLabel.text = @"点击更换头像";
    changeHeaderLabel.textColor = COLOR_RGBA(128, 225, 213, 1.0);
    changeHeaderLabel.font = [UIFont systemFontOfSize:15 * FONTSIZE];
    [self.infoScrollView addSubview:changeHeaderLabel];
    
    self.topInfoView = [[UserInfoImgView alloc] initWithFrame:CGRectMake(23 * FONTSIZE, 173 * FONTSIZE, SCREENW - 36 * FONTSIZE, 135 * FONTSIZE)];
    [self.infoScrollView addSubview:_topInfoView];
    
    self.bottomInfoView = [[UserInfoImgView alloc] initWithFrame:CGRectMake(23 * FONTSIZE, 328 * FONTSIZE, SCREENW - 36 * FONTSIZE, 135 * FONTSIZE)];
    [self.infoScrollView addSubview:_bottomInfoView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(receiveKeyBoard)];
    [self.view addGestureRecognizer:tap];
}

- (void)loadData
{
    self.topInfoView.topView.titleLabel.text = @"昵称";
    [self.topInfoView.topView hideArrow:YES];
    self.topInfoView.midView.titleLabel.text = @"性别";
    self.topInfoView.bottomView.titleLabel.text = @"生日";
    
    self.bottomInfoView.topView.titleLabel.text = @"签名";
    self.bottomInfoView.midView.titleLabel.text = @"邮箱";
    [self.bottomInfoView.midView hideArrow:YES];
    self.bottomInfoView.bottomView.titleLabel.text = @"职业";
    [self.bottomInfoView.bottomView hideArrow:YES];
    
    self.topInfoView.midView.txtField.delegate = self;
    self.topInfoView.bottomView.txtField.delegate = self;
    self.bottomInfoView.topView.txtField.delegate = self;
    self.bottomInfoView.midView.txtField.delegate = self;
    self.bottomInfoView.bottomView.txtField.delegate = self;
}

- (void)receiveKeyBoard
{
    [self.topInfoView.topView.txtField resignFirstResponder];
    [self.topInfoView.midView.txtField resignFirstResponder];
    [self.topInfoView.bottomView.txtField resignFirstResponder];
    [self.bottomInfoView.topView.txtField resignFirstResponder];
    [self.bottomInfoView.midView.txtField resignFirstResponder];
    [self.bottomInfoView.bottomView.txtField resignFirstResponder];
    [self.infoScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField == self.topInfoView.midView.txtField) {
        
    } else if (textField == self.topInfoView.bottomView.txtField) {
        
    } else if (textField == self.bottomInfoView.topView.txtField) {
        
    } else if (textField == self.bottomInfoView.midView.txtField) {
        [self.infoScrollView setContentOffset:CGPointMake(0, 160 * FONTSIZE) animated:YES];
    } else if (textField == self.bottomInfoView.bottomView.txtField) {
        [self.infoScrollView setContentOffset:CGPointMake(0, 200 * FONTSIZE) animated:YES];
    }
}

- (void)changeInfoFinish
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
